<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>宇成建筑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../statics/css/font.css">
    <link rel="stylesheet" href="../statics/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="../statics/css/xadmin.css">
    <link rel="stylesheet" href="../statics/css/style.css">
</head>

<body class='labelAuto'>
<div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="welcome.html">首页</a>
            <a href="javascript:;">施工管理</a>
            <a>
                <cite>班组列表</cite>
            </a>
        </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right:10px"
       onclick="window.history.go(-1)" title="后退">
        <i class="iconfontBlod" style="line-height:30px">&#xe74f;</i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-d layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body tableCardBody">
                    <table class="layui-table" id="lists" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type='text/html' id='toolbar'>
    <button class="layui-btn add" type="button" auth="addGroupMember">添加</button>
</script>
<script src="../statics/plugins/layui/layui.js" charset="utf-8"></script>
<script src='../statics/plugins/jQuery-3.2.1/jquery-3.2.1.min.js'></script>
<script type="text/javascript" src="../statics/plugins/X-admin/xadmin.js"></script>
<script type="text/javascript" src="../statics/js/public.js?v=1129"></script>
<script type="text/javascript">
    layui.use(['form', 'layer', "table", "laydate"], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer;
        var groupId = getQueryString('groupId');
        var projectId = getQueryString('projectId');
        // 异步数据加载
        var lists = table.render({
            elem: '#lists', //绑定DOM元素
            id: 'lists', //table的id
            title: '人员列表',
            height: 'full-100',
            contentType: "application/json; charset=utf-8",
            url: url + '/hrm/group/memberLists', //数据接口地址
            request: {
                pageName: 'page', //页码的参数名称，默认：page
                limitName: 'length' //每页数据量的参数名，默认：limit
            },
            method: 'POST',
            parseData: function (res) {
                return {
                    "code": res.code, //解析接口状态
                    "data": res.data,
                    "msg": res.msg,
                };
            },
            where: {
                groupId: groupId,
                token: getToken()
            },
            toolbar: '#toolbar',
            defaultToolbar: ['filter'],
            page: false, //开启分页
            limit: 10, //默认每页记录条数
            limits: [10, 20, 50], //每页记录条数可选数量
            cols: [
                [ //表头
                    {field: '', title: '编号', type: 'numbers', width: '8%'},
                    {field: 'employeeName', title: '项目'},
                    {field: 'jobNumber', title: '工号'},
                    {
                        field: 'status', title: '状态', templet: function (d) {
                            return `${d.status == 1 ? "在岗" : d.status == 2 ? "待岗" : d.status == 3 ? "离职" : "请假"}`
                        }
                    },
                    {
                        field: 'isLeader', title: '班组长', templet: function (d) {
                            return `${d.isLeader == 1 ? "是" : "否"}`
                        }
                    },
                    {
                        field: '', title: '操作', templet(d) {
                            return `
                            <button class='delete layui-btn' lay-event='delete' data-id=${d.id} name=${d.professionId}  auth="delGroupMember">删除</button>
                        `
                        }
                    }
                ]
            ],
            response: {
                statusName: 'code', //数据状态的字段名称，默认：code
                statusCode: 100000, //成功的状态码，默认：0
                msgName: 'msg', //状态信息的字段名称，默认：msg
                countName: 'count', //数据总数的字段名称，默认：count
                dataName: 'data' //数据列表的字段名称，默认：data
            },
            done:function(){
                permission();
            }
        });
        table.on('tool(test)', function (data) {
            if (data.event == 'delete') {
                layer.open({
                    type: 1,
                    area: ['40%', '30%'],
                    title: "删除",
                    content: `
                        <form class='layui-form layerOpen'>
                            <div class='layui-item'>
                                <div class='layui-inline'>
                                    <label class='layui-form-label'>确定从班组中删除此名工人吗？</label>
                                </div>
                            </div>
                        </form>
                    `,
                    btn: ['确定', '关闭'],
                    skin: 'my-skin',
                    yes: function () {
                        $.ajax({
                            url: url + '/hrm/group/delMember',
                            type: 'post',
                            data: {
                                id: data.data.id,
                                token: getToken()
                            },
                            success: function (r) {
                                if (r.code == 100000) {
                                    tips('删除', r);
                                    setTimeout(function () {
                                        layer.closeAll();
                                        table.reload('lists');
                                    }, 2000)
                                } else {
                                    tips('删除', r);
                                }
                            }
                        })
                    }
                })
            }
        })

        $('body').on('click', '.add', function () {
            var option = '<option value="">-</option>';
            $.ajax({
                url: url + "/hrm/group/notInGroup",
                type: "POST",
                async: false,
                data: {
                    projectId: projectId,
                    token:getToken()
                },
                success: function(r) {
                    if(r.code == 100000) {
                        for (var i=0 ; i<r.data.length;i++){
                            option+=`<option value="${r.data[i].id}">${r.data[i].name}</option>`
                        }
                    } else {
                        tips('查询',r);
                    }
                }
            })
            layer.open({
                type: 1,
                title: "添加",
                area: ['40%', '60%'],
                content: `
                    <form class='layui-form layerOpen'>
                        <div class="layui-item">
                            <input type="hidden" class="layui-input" name="id">
                            <div class='layui-inline'>
                                <label class="layui-form-label">工人</label>
                                <div class="layui-input-block">
                                    <select name="employeeId"  lay-search>
                                        ${option}
                                    </select>
                                </div>
                            </div>
                        </div>
                    </form>
                `,
                btn: ['确认', '取消'],
                skin: 'my-skin',
                success:function(){
                    form.render();
                },
                yes: function(index, layero) {
                    var employeeId = $('select[name=employeeId]').val();
                    $.ajax({
                        url: url + "/hrm/group/addMember",
                        type: "POST",
                        async: false,
                        data: {
                            groupId: groupId,
                            projectId:projectId,
                            employeeId: employeeId,
                            token:getToken()
                        },
                        success: function(r) {
                            if(r.code == 100000) {
                                tips('添加组员',r);
                                setTimeout(function(){
                                    layer.closeAll();
                                    table.reload('lists');
                                },2000)
                            } else {
                                tips('添加组员',r);
                            }
                        }
                    })
                }
            })
        })
    });

</script>

</html>